﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/3/2009
 * Time: 1:10 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using Buaya.Model;

namespace Buaya.Gui
{
	/// <summary>
	/// Description of TaxCodeListForm.
	/// </summary>
	public partial class TaxCodeListForm : BaseForm
	{
		public TaxCodeListForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			listView1.Resize += delegate { columnHeader2.Width = listView1.Width - 22 - (columnHeader1.Width + columnHeader3.Width); };
			refreshToolStripMenuItem.Click += delegate { OnActivated(null); };
			newToolStripMenuItem.Click += delegate { MainForm.Instance.AddChild(new TaxCodeForm()); };
		}
		
		[System.ComponentModel.EditorBrowsableAttribute()]
		protected override void OnActivated(EventArgs e)
		{
			base.OnActivated(e);
			Model = SessionFacade.FindAllTaxCodes();
		}
		
		protected override void OnModelChanged(EventArgs e)
		{
			base.OnModelChanged(e);
			listView1.Items.Clear();
			foreach (TaxCode t in Model as IList<TaxCode>) {
				ListViewItem li = listView1.Items.Add(t.Code);
				li.SubItems.Add(t.Description);
				li.SubItems.Add(t.PersonalExemption.ToString("0.00"));
				Util.SwfUtility.AlternateColor(li);
			}
		}
		
		void EditToolStripMenuItemClick(object sender, EventArgs e)
		{
			if (listView1.SelectedItems.Count > 0) {
				TaxCode t = (Model as IList<TaxCode>)[listView1.SelectedItems[0].Index];
				MainForm.Instance.AddChild(new TaxCodeForm(t), "Edit Tax Code");
			}
		}
	}
}
